package com.indexingsystem.boss.aspect;



import java.lang.reflect.Method;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

@Aspect
public class DataSourceAspect {
	
   /* @Before("execution(* com.indexingsystem.boss.admin.mapper.WechatSharesMapper.insertSelective(..))")
    public void before(){
        System.out.println("前置通知....");
    }*/
	
	
	/*
	 public void before(JoinPoint point){
	        Object target = point.getTarget();
	        String method = point.getSignature().getName();
	        Class<?>[] classz = target.getClass().getInterfaces();
	        Class<?>[] parameterTypes = ((MethodSignature) point.getSignature()).getMethod().getParameterTypes();
	        try {
	            Method m = classz[0].getMethod(method, parameterTypes);
	            if (m != null && m.isAnnotationPresent(DataSource.class)) {
	                // 访问mapper中的注解
	                DataSource data = m.getAnnotation(DataSource.class);
	                switch (data.value()) {
	                    case masterDataSource:
	                        DynamicDataSourceHolder.setDataSourceType(DataSourceType.masterDataSource);
	                     
	                        break;
	                    case slaverDataSource:
	                        DynamicDataSourceHolder.setDataSourceType(DataSourceType.slaverDataSource);
	                      
	                        break;
	                }
	            }
	        } catch (Exception e) {
	          
	            // 若出现异常，手动设为主库
	            DynamicDataSourceHolder.setDataSourceType(DataSourceType.masterDataSource);
	        }
	    }*/
    
    
    /**
     * 环绕通知
     * @param joinPoint 可用于执行切点的类
     * @return
     * @throws Throwable
     */
    @Around("execution(* com.indexingsystem.boss.admin.mapper.WechatSharesMapper.insertSelective(..))")
    public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
        System.out.println("环绕通知前....");
        Object obj= (Object) joinPoint.proceed();
        System.out.println("环绕通知后....");
        return obj;
    }
}
